package com.xhs.service.impl;

import com.alibaba.fastjson2.JSONObject;
import com.xhs.dto.request.SendHttpParams;
import com.xhs.message.ReturnResult;
import com.xhs.service.SendHttpService;
import com.xhs.utils.SendHttpUtil;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @desc:
 * @projectName: spring-boot-demo
 * @author: xhs
 * @date: 2024-06-08 16:51
 * @version: JDK 1.8
 */
@Service
public class SendHttpServiceImpl implements SendHttpService {

    /**
     * 发送Get请求
     *
     * @param param 入参
     * @return ReturnResult
     */
    @Override
    public ReturnResult<Object> sendGet(SendHttpParams param) {
        Map<String, String> headerMap = new HashMap<>(16);
        headerMap.put("sing", "ed97425f7fb77c97805b17c77be4a94b");
        headerMap.put("timestamp", "1693125200167");
        Map<String, Object> bodyMap = new HashMap<>(16);
        bodyMap.put("httpCode", "FC1012");
        bodyMap.put("httpUrl", param.getHttpUrl());
        JSONObject jsonObject = SendHttpUtil.sendGet(param.getHttpUrl(), headerMap, bodyMap);
        return ReturnResult.success("请求成功!").setData(jsonObject);
    }

    /**
     * 发送post请求
     *
     * @param param 入参
     * @return ReturnResult
     */
    @Override
    public ReturnResult<Object> sendPost(SendHttpParams param) {
        Map<String, String> headerMap = new HashMap<>(16);
        headerMap.put("sing", "ed97425f7fb77c97805b17c77be4a94b");
        headerMap.put("timestamp", "1693125200167");
        Map<String, Object> bodyMap = new HashMap<>(16);
        bodyMap.put("httpCode", "FC1013");
        bodyMap.put("httpUrl", param.getHttpUrl());
        JSONObject jsonObject = SendHttpUtil.sendPost(param.getHttpUrl(), "", headerMap, bodyMap);
        return ReturnResult.success("请求成功!").setData(jsonObject);
    }
}
